package com.eascs.p2p.investor.dubbo;

import java.math.BigDecimal;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.app.dao.PageResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.p2p.common.entity.InvestorEntity;
import com.eascs.p2p.common.entity.InvestorRecordEntity;
import com.eascs.p2p.common.service.InvestorService;
import com.eascs.p2p.common.vo.InvestorVO;import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.p2p.investor.server.InvestorServiceInner;

@Service
public class InvestorDubboServiceImpl implements InvestorService {
	private static Logger logger = LoggerFactory.getLogger(InvestorDubboServiceImpl.class);

	@Autowired
	private InvestorServiceInner investorService;

	@Override
	public ModelResult<InvestorEntity> queryInvestorByLogin(String account, String password) {
		InvestorEntity investor = new InvestorEntity(account, password);
		return investorService.queryInvestor(investor);
	}
	
	@Override
	public ModelResult<InvestorEntity> queryInvestorById(String investorId) {
		InvestorEntity investor = new InvestorEntity();
		investor.setId(investorId);
		return investorService.queryInvestor(investor);
	}


	@Override
	public ModelResult<Boolean> register(InvestorEntity investor) {
		return investorService.register(investor);
	}

	@Override
	public ModelResult<List<InvestorRecordEntity>> queryInvestorRecordList(InvestorRecordEntity investorRecord) {
		return investorService.queryInvestorRecordList(investorRecord);
	}

	@Override
	public ModelResult<Boolean> buyInvest(InvestorEntity investor, String investObjId, BigDecimal investMoney) {
		ModelResult<Boolean> result = new ModelResult<>();
		try {
			return investorService.buyInvest(investor, investObjId, investMoney);
		} catch (Exception e) {
			logger.error("下单失败, account:{}, error:{}", investor.getAccount(), e.getMessage());
			result.withError("InvestorServiceInnerImpl.buyInvest", "下单失败");
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public ModelResult<PageResult<Object[]>> findPageInvestorEntity(InvestorVO vo) {
		return investorService.findPageInvestorEntity(vo);
	}

	@Override
	public ModelResult<List<Object[]>> getInvestorNameorMobile(String keywords) {
		
		return investorService.getInvestorNameorMobile(keywords);
	}

	@Override
	public ModelResult<Boolean> updateStatus(String id, int status) {
		
		return  investorService.updateStatus(id, status);
	}

	@Override
	public ModelResult<Boolean> saveTradePasswrod(String id,String password){
		return  investorService.saveTradePasswrod(id, password);
	}
	
	@Override
	public ModelResult<String> getTradePasswrod(String id){
		return  investorService.getTradePasswrod(id);
	}	@Override
	public ModelResult<Boolean> updateInvestor(InvestorEntity investor) {
		return investorService.updateInvestor(investor);
	}
	@Override
	public ModelResult<InvestorEntity> queryInvestorByAccount(String account) {
		return investorService.queryInvestorByAccount(account);
	}
}
